package com.ptswitch.material.pages.material;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.slf4j.Logger;

import com.ptswitch.material.pages.base.MaterialBasePage;
import com.ptswitch.material.service.MaterialService;
import com.ptswitch.material.util.HlogConstants;

public class ClearMaterial extends MaterialBasePage {
    @Inject
    private MaterialService materialSer;
    @InjectPage
    private ListMaterial listMaterial;
    @Inject
    private Logger logger;

    @OnEvent(value = EventConstants.ACTIVATE)
    Object deleteAll() {
        checkUserIsAdmin();
        materialSer.deleteAll();
        hlog(HlogConstants.deleteAllMaterial);
        logger.debug("clear material");
        return listMaterial.initialize();
    }
}
